﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web4Comment.Service;

namespace Web4Comment
{
    public partial class personal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null && Session["user_id"] != null)
            {
                Response.Redirect("./profile.aspx?user=" + Session["username"]);
            }

            if (!IsPostBack)
            {
                warningLabel.Visible = false;
            }

        }

        protected void OnLogonButtonClicked(object sender, EventArgs e)
        {
            int user_id = Service.UserService.logon(usernameTextBox.Text.Trim(), passwordTextBox.Text.Trim());
            if (user_id != 0)
            {
                Session["username"] = usernameTextBox.Text.Trim();
                Session["user_id"] = user_id;
            }
            else
            {
                warningLabel.Visible = true;
                return;
            }

            Response.Redirect("./profile.aspx?user=" + Session["username"]);
        }
    }
}